package cn.psvmc.cxzapi.controller.system;

import cn.psvmc.cxzapi.model.system.TPlatformSet;
import cn.psvmc.cxzapi.response.Result;
import cn.psvmc.cxzapi.response.ResultGenerator;
import cn.psvmc.cxzapi.service.system.TPlatformSetService;
import cn.psvmc.cxzapi.util.ToolUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 平台配置管理
 * @Author auto
 * @Date 2024-08-15
 */
@RestController
@RequestMapping("/platform_set")
public class TPlatformSetController {

    @Resource
    private TPlatformSetService tPlatformSetService;

    /**
    * @Author auto 2024-08-15 更新平台配置表
    * @Param tPlatformSet 平台配置表模型
    * @Return cn.psvmc.cxzapi.response.Result
    */
    @PostMapping("/edit")
    public Result edit(@RequestBody TPlatformSet tPlatformSet) {
        ToolUtils.validation(new Object[]{
                tPlatformSet.getSettlementRatio(), "订单结算比例", 1
                , tPlatformSet.getRenewalRate(), "续租每期费率", 1
                , tPlatformSet.getRecivePhone(), "接收消息手机号", 2
        });
        int updateResult = tPlatformSetService.edit(tPlatformSet);
        if (updateResult > 0) {
            return ResultGenerator.genSuccessResult("更新成功！");
        }
        return ResultGenerator.genFailResult("更新失败！");
    }

    /**
    * @Author auto 2024-08-15 查询平台配置表详情
    * @Param entity
    * @Return cn.psvmc.cxzapi.response.Result
    */
    @PostMapping("/detail")
    public Result detail() {
        return ResultGenerator.genSuccessResult("查询成功", tPlatformSetService.detail());
    }
}
